/**
 * 月汇率 - 编辑页面
 * @author yuan_rz
 * @date 2019/01/09 13:42
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            isAdd: false,
            isDetail: false,
            form: '',
            rules: {
                GWEK001: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWEK002: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWEKDOCDATE: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWEKACTI: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ]
            },
            selectOptions:{
                sys_y_n : app.datas_('sys_y_n')
            }
        },
        callObj,
        moduleName,
        pageVue
    ;

    var gwei014Edit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwei014_edit',
                _loadTplsFull: [{
                    dom: 'common_open_window', tpl: 'common/_open_window'
                }]
            }, win);
        },
        editData: function () {
            app.ajax({
                xurl: 'base/gwei014/editData',
                xdata: vueData.form,
                loading: true,
                okmsg: moduleName + '信息修改成功',
                cb: function (result) {
                    if (result.ok) {
                        //同步更新缓存对应的值
                        callObj.obj.update(result.xdata);
                        layer.close(callObj.layOpenIndex);
                    }
                }
            });
        },
        addData: function () {
            app.ajax({
                xurl: 'base/gwei014/addData',
                xdata: vueData.form,
                loading: true,
                okmsg: moduleName + '信息保存成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule('gwei014').reloadTableCurr();
                        layer.close(callObj.layOpenIndex);
                    }
                }
            });
        },
        _call: function (tagData) {
            pageVue.$refs['form'].resetFields();
            callObj = tagData;
            moduleName = tagData.moduleName;
            if(tagData.is_detail){
                vueData.isDetail = true;
            }else {
                vueData.isDetail = false;
            }
            if (tagData.is_add) {
                vueData.isAdd = true;
                app.extendUpLow({
                    target: vueData.form,
                    res: {
                        GWEK001:  '',
                        GWEK002:  '',
                        GWEKDOCDATE: '',
                        GWEKACTI: 'Y',
                        GWEK104: 'RMB'
                    },
                    reset: true
                });
            } else {
                vueData.isAdd = false;
                app.extendUpLow({
                    target: vueData.form,
                    res: [callObj.obj.data,
                        {
                            oldGWEK001 : callObj.obj.data.GWEK001,
                            oldGWEK002 : callObj.obj.data.GWEK002
                        }],
                    reset: true
                });
            }

        },
        _ready: function () {
            vueData.form = app.fields_(['base_gwei014']);
            pageVue = new Vue({
                el: '#gwei014_edit',
                data: vueData,
                watch:{
                    'form.GWEK008':function (data) {
                        vueData.form.GWEK003 = data;
                        vueData.form.GWEK004 = data;
                        vueData.form.GWEK005 = data;
                        vueData.form.GWEK006 = data;
                        vueData.form.GWEK007 = data;
                    }
                },
                methods: {
                    cancel: function () {
                        layer.close(callObj.layOpenIndex);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                if (vueData.isAdd) {
                                    self.addData();
                                } else {
                                    self.editData();
                                }
                            }
                        });
                    },
                    openGwek001:function () {
                        self._openTplFull({
                            tag: 'common_open_window',
                            tagData: {
                                config: {
                                    method:'q_gwac001',
                                    columnList: [
                                        {label: '币种编号', prop: 'GWAC001', width: '150'},
                                        {label: '说明', prop: 'GWACL003', width: '150'},
                                    ],
                                },
                                cb: function (data) {
                                    vueData.form.GWEK001 = data.GWAC001;
                                }
                            },
                            index: 0,
                            openOpts: {
                                title: '选择币种信息',
                                area: ['600px', '465px']
                            }
                        });
                        // self._openTplFull({
                        //     tag: 'common_open_bz',
                        //     tagData: {
                        //         cb:function (data) {
                        //             vueData.form.GWEK001 = data.GWAC001;
                        //         }
                        //     },
                        //     index:0,
                        //     openOpts: {
                        //         title: '选择币种',
                        //         area:['600px', '470px']
                        //     }
                        // });
                    }
                },
                created: function () {
                    self._setEleIsReady('gwei014_edit');
                }
            });
        },
        _lazy: function () {
            this._super();
        }
    });

    return new gwei014Edit();

});
